package com.wobangkj.common.service.impl;

import com.wobangkj.common.model.crud.Collect;
import com.wobangkj.common.repository.CollectRepository;
import com.wobangkj.common.service.CollectService;
import com.wobangkj.tool.api.result.Result;
import com.wobangkj.tool.util.sql.CrudUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Slf4j
public class CollectServiceImpl implements CollectService {

    @Autowired
    private CollectRepository repository;

    @Override
    public Object delete(Long id) {
        return CrudUtil.delete(id, repository);
    }

    @Override
    public Object create(Collect collect) {
        try {
            Collect createData = repository.save(collect);
            // 使用 uuid 作为源 token
            //String     token = UUID.randomUUID().toString().replace("-", "");
            //TokenModel model = new TokenModel(createData.getId(), token);
            // 30 分钟有效期
            //cacheManager.set(model.getToken(), new CacheModel(TOKEN_MINUTE, model));
            return Result.GetMapData(Result.CodeCreate, Result.MsgCreate);//, model);
        } catch (Exception e) {
            return Result.GetMapData(Result.CodeSql, e.getCause().getCause().getMessage());
        }
    }

    @Override
    public List<Collect> findById(String collector_id, String collect_text_id, String collect_class) {
        return repository.findById(collector_id,collect_text_id,collect_class);
    }

    @Override
    public Long findCollect(String collector_id, String collect_text_id, String collect_class) {
        return repository.findCollect(collector_id,collect_text_id,collect_class);
    }

    @Transactional
    @Override
    public void updateShareNumById(Long id) {
        repository.updateShareNumById(id);
    }

    @Transactional
    @Override
    public void updateJobNumById(Long id) {
        repository.updateJobNumById(id);
    }

    @Transactional
    @Override
    public void deleteShareNumById(Long id) {
        repository.deleteShareNumById(id);
    }

    @Transactional
    @Override
    public void deleteJobNumById(Long id) {
        repository.deleteJobNumById(id);
    }

}
